import requests, os



def payforproductnameinquiries(header, num, pagenum, userName,productname):
    """
    func: 查询支付配置接口
    :param header: 请求头
    :param num: 数据条数
    :param pagenum: 页面数量
    :param productname: 模块名
    :return:
    """
    url = os.getenv('HOST') + '/pay/product/list'
    data = {
        "pageNum": num,
        "numPerPage": pagenum,
        "userName":userName ,
        "productName": productname
    }
    return requests.post(url, headers=header, data=data)



def addAPaymentConfiguration(header, payproductCode,payWayCode,payTypeCode,payRate):
    """
    func: 设置支付方式
    :param payProductCode: 支付产品编码
    :param payWayCode:支付方式
    :param payTypeCode:支付类型
    :param payRate:支付费率
    :return:
    """
    url = os.getenv('HOST') + '/pay/way/add'
    data = {
        "payProductCode": payproductCode,
        "payWayCode": payWayCode,
        "payTypeCode": payTypeCode,
        "payRate": payRate
    }
    return requests.post(url, headers=header, data=data)





def payForProductListings( header, pagenum, numperpage, productName):
    """
    func 查询支付产品
    :param header: 请求头
    :param pagenum: 页码
    :param numperpage: 页面数据数量
    :param productName: 产品名称
    :return:
    """
    url = os.getenv('HOST')+'/pay/product/list'
    data = {
        "pageNum": pagenum,
        "numPerPage": numperpage,
        "productName": productName
    }

    return requests.post(url, headers=header, data=data)


def addAPaymentProduct(header, productName, productDesc):
    """
    func 添加支付产品
    :param header: 请求头
    :param productName: 产品名称
    :param productDesc: 产品描述
    :return:
    """
    url = os.getenv('HOST')+'/pay/product/add'
    data =   {"productCode": productName,
        "productName": productDesc
      }

    return requests.post(url, headers=header, data=data)


def paymentProductsArePutOnTheShelves(header, code):
    """
    func 支付产品上架
    :param header: 请求头
    :code 支付产品编号
    :return:
    """
    url = os.getenv('HOST')+f'/pay/product/audit?productCode={code}&auditStatus=YES'

    return requests.get(url , headers=header)



def paymentProductsAreRemovedFromTheShelves( header, code):
    """
    func 支付产品下架
    :param header:请求头
    :code 支付产品编号
    :return:
    """
    url = os.getenv('HOST')+f'/pay/product/audit?productCode={code}&auditStatus=NO'
    return requests.get(url , headers=header)


def deleteAPaymentProduct( header, code):
    """
    func 删除支付产品
    :param header:请求头
    :return:
    """
    url = os.getenv('HOST')+f'/pay/product/delete?productCode={code}'
    return requests.get(url , headers=header)




def addAPaymentConfigurationg( header, userNo, userName, productCode, productName):
    """

    :param header: 请求头
    :param userNo: 用户编号
    :param userName: 用户姓名
    :param productCode: 产品编码
    :param productName: 产品名称
    :return:
    """

    url = os.getenv('HOST')+'/pay/config/add'
    data = {
   "user.userNo": userNo,
   "user.userName": userName,
   "product.productCode": productCode,
   "product.productName": productName,
   "fundIntoType": "PLAT_RECEIVES",
   "riskDay": "1",
   "isAutoSett": "NO",
   "securityRating": "MD5"
    }
    return requests.post(url, headers=header, data=data)


def bindBankCard(header, userno, username, bankcode, bankat, bankan, banka, cardno, mobileno, street):
    """
    func: 绑定银行卡
    :param header: 请求头
    :param userno: 用户编号
    :param username: 用户名
    :param bankcode: 银行名称
    :param bankat: 银行账户类型
    :param bankan: 银行开户名
    :param banka: 银行账号
    :param cardno: 证件号码
    :param mobileno: 手机号
    :param street: 开户行详细地址
    :return:
    """
    url = os.getenv('HOST')+'/pay/config/editBank'
    data = {
  "userNo": userno,
  "userName": username,
  "bankCode": bankcode,
  "bankAccountType": bankat,
  "bankAccountName": bankan,
  "bankAccountNo": banka,
  "cardType": "",
  "cardNo": cardno,
  "mobileNo": mobileno,
  "street": street
}
    return requests.post(url, headers=header, data=data)



def add_users( header, name, phone):
    """
    func:添加用户
    :param header:请求头
    :param name:用户姓名
    :param phone:电话号码
    :return:
    """
    url = os.getenv('HOST') + '/user/info/add'
    data = {
  "userName": name,
  "mobile": phone,
  "password": "123456"
}
    return requests.post(url, headers=header, data=data)


def delete_bink_delete(header, userno):
    """
    func:删除绑定支付方式
    :param header: 请求头
    :param userno: 用户编号
    :return:
    """
    url = os.getenv('HOST') + f'/pay/config/deleteBank?userNo={userno}'
    return requests.get(url, headers=header)